<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .title{
            width: 800px;
            margin: 0 auto;
            border: 1px solid #ccc;
            padding: 10px;
        }
        .share{
            margin: 5px 0;
            color: #ccc;
        }
        li{
            list-style: none;
            line-height: 60px;
            border-bottom: 1px solid #ccc;
        }
        .color{
            color: #999;
        }
        .fr{
            float: right;
            color: red;
        }
        .fr img{
            vertical-align: middle;
            width: 15px;
            margin-right: 5px;
        }
    </style>
</head>
<body>
    <div id="box">
        <div class="title">
            <h4>{{arr.title}}</h4>
            <p class="share">
                ·分享：问答 ·{{arr.visit_count}}次访问·发布于{{arr.last_reply_at | formatDate}}·作者·{{arr.author.loginname}}         
            </p>
            <div v-html="arr.content">{{arr.content}}</div>
            <ul>
                <li v-for="(item,index) in arr1">
                    <h5>{{item.author.loginname}} <span class="color">{{index+1}}楼</span> 
                        <span class="fr"><img src="./images/cart.jpg" alt="">{{item.ups.length}}</span> 
                    </h5>
                    <p v-html="item.content">{{item.content}}</p>
                </li>
            </ul>
        </div>
    </div>
    <script src="./js/vue.js"></script>
    <script src="./js/axios.min.js"></script>
    <script>
        // 月份、日期、小时等小于10前面补0
        let padDate = (value => {
            return value < 10 ? '0' + value : value;
        })
        let vm = new Vue({
            el:"#box",
            data:{
                arr:[],
                arr1:[]
            },
            beforeCreate(){
                axios.get('https://cnodejs.org/api/v1/topic/5ae140407b0e8dc508cca7cc',)
                .then(res=>{
                    console.log(res.data.data);
                    this.arr = res.data.data;
                    console.log(res.data.data.replies);
                    this.arr1 = res.data.data.replies;
                }).catch(err=>{
                    console.log(err);
                })
            },
            filters: {
                formatDate: (value => {
                    let date = new Date(value);
                    let year = date.getFullYear();
                    let month = padDate(date.getMonth() + 1);
                    let day = padDate(date.getDate());
                    let hours = padDate(date.getHours());
                    let minutes = padDate(date.getMinutes());
                    let seconds = padDate(date.getSeconds());
                    return year + '-' + month + '-' + day + '-' + ' ' + hours + ':' + minutes + ':' + seconds;
                })
            },
        })
    </script>
</body>
</html>